package com.cal.calonecal.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cal.calonecal.common.Response;
import com.cal.calonecal.pojo.entity.Answer;
import com.cal.calonecal.pojo.entity.Choose;
import com.cal.calonecal.pojo.entity.Paper;
import com.cal.calonecal.pojo.entity.Problem;
import com.cal.calonecal.service.IPaperService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.Put;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 76004
 * @apiNote
 * @date 2023/6/17 13:05
 */
@RestController
@RequestMapping("/paper")
@Api("试卷相关")
@CrossOrigin
public class PaperController {
    @Autowired
    private IPaperService paperService;


    @PostMapping("/add")
    public Response<Void> add(@RequestBody Paper paper) {
        return paperService.add(paper);
    }

    @PostMapping("/delete")
    public Response<Void> delete(long id) {
        return paperService.delete(id);
    }

    @PutMapping("/update")
    public Response<Void> update(Paper paper) {
        return paperService.update(paper);
    }

    @GetMapping("/select-by-id")
    public Response<Paper> selectById(Long id) {
        return paperService.selectById(id);
    }

    @GetMapping("/select-by-user-id")
    @ApiOperation("查询某个老师创建的试卷")
    public Response<IPage<Paper>> selectByUserId(Integer pageNum, Integer pageSize) {
        return paperService.selectByUserId(pageNum, pageSize);
    }

    @GetMapping("/select-page")
    @ApiOperation("分页查询所有试卷")
    public Response<IPage<Paper>> selectPage(Integer pageNum, Integer pageSize) {
        return paperService.selectPage(pageNum, pageSize);
    }

    @PostMapping("/judge")
    @ApiOperation("评测")
    public Response<Paper> judge(Paper paper) {
        return paperService.judge(paper);
    }

    @GetMapping("/select-user-paper-records")
    @ApiOperation("分页查询用户做题记录")
    public Response<IPage<Paper>> selectUserPaperRecords(Integer pageNum, Integer pageSize) {
        return paperService.selectUserPaperRecords(pageNum, pageSize);
    }

    @GetMapping("/select-user-record")
    @ApiOperation("获取用户在某个试卷的做题记录")
    public Response<Paper> selectUserRecord(Long paperId) {
        return paperService.selectUserRecord(paperId);
    }

    @GetMapping("/publish")
    @ApiOperation("发布")
    public Response<Void>publish(Long paperId, Long classId){
        return paperService.publish(paperId, classId);
    }

    @DeleteMapping("/delete-problem-in-paper")
    @ApiOperation("删除试卷中的题目")
    public Response deleteProblemInPaper(Long problemId){
        return paperService.deleteProblemInPaper(problemId);
    }

    @PutMapping("/add-problem-to-paper")
    @ApiOperation("添加题目到试卷里")
    public Response addProblem2Paper(Long problemId, Long paperId){
        return paperService.addProblem2Paper(problemId, paperId);
    }
}
